cmake_minimum_required(VERSION 3.27)
set(PROJ_NAME case30)
project(${PROJ_NAME})


function(copy_attached_files target_name files)
    foreach(relfilename IN LISTS files)
        file(RELATIVE_PATH relative_path ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})

        set(src_filepath ${CMAKE_SOURCE_DIR}/${relative_path}/${relfilename})
        set(dst_filepath ${CMAKE_BINARY_DIR}/$<CONFIG>/${relative_path}/${relfilename})

        add_custom_command(OUTPUT ${dst_filepath}
            COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src_filepath} ${dst_filepath}
            DEPENDS ${src_filepath}
            )

        list(APPEND dependent_files ${dst_filepath})
    endforeach()
    
    add_custom_target(${target_name}_AssetFiles
        DEPENDS ${dependent_files}
        )
        
    get_target_property(target_folder ${target_name} FOLDER)
    set_target_properties(${target_name}_AssetFiles PROPERTIES FOLDER ${target_folder})

    add_dependencies(${target_name} ${target_name}_AssetFiles)

endfunction() # copy_attached_files

add_executable(${PROJ_NAME}
    main.cpp
    )

# add_custom_command(OUTPUT
#     ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/data/input.txt
#     COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/data"
#     COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/data/input.txt" "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/data/input.txt"
#     DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/data/input.txt"
#     )

# add_custom_target(DataFiles
#     DEPENDS
#     ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/data/input.txt
#     COMMENT "Build DataFiles target"
#     )

# add_dependencies(${PROJ_NAME} DataFiles)

set(AssetFiles 
    "input.txt"
    "data/input2.txt"
    "data/input.txt"
    "data/subfolder/input.txt"
)

copy_attached_files(${PROJ_NAME} "${AssetFiles}")
